
package com.example.viewactivity;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;

import com.example.entity.CityInfo;
import com.example.rewrite.SwipeAdapter;
import com.example.rewrite.SwipeListView;
import com.example.weather.*;
public class City_view extends Activity {
	private List<CityInfo> data = new ArrayList<CityInfo>();
    private SwipeListView mListView;
    private ImageView add_view;
    private TabHost tabHostRef;
    private TabHost tabhost;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.city_manage);
        System.out.println("I'm here");
       /*tabHostRef=this.getTabHost();
        LayoutInflater.from(this).inflate(R.layout.page1,tabHostRef.getTabContentView(),true);
        LayoutInflater.from(this).inflate(R.layout.page2,tabHostRef.getTabContentView(),true);
        LayoutInflater.from(this).inflate(R.layout.city_manage,tabHostRef.getTabContentView(),true);
        LayoutInflater.from(this).inflate(R.layout.page4,tabHostRef.getTabContentView(),true);
        tabHostRef.addTab(tabHostRef.newTabSpec("天气查询").setIndicator("天气查询").setContent(R.id.page1));
        tabHostRef.addTab(tabHostRef.newTabSpec("七日趋势").setIndicator("七日趋势").setContent(R.id.page2));
        tabHostRef.addTab(tabHostRef.newTabSpec("城市管理").setIndicator("城市管理").setContent(R.id.city_manage));
        tabHostRef.addTab(tabHostRef.newTabSpec("指数信息").setIndicator("指数信息").setContent(R.id.page4));
        tabHostRef.setCurrentTab(2);
        tabHostRef.setOnTabChangedListener(new OnTabChangeListener() {
			
			@Override
			public void onTabChanged(String arg0) {
				// TODO Auto-generated method stub
				Log.v("单击了=====",""+ arg0);
				Intent i = new Intent();
				if(arg0=="天气查询"){
					i.setClass(City_view.this,TodayWeatherActivity.class);
					startActivity(i);
				}
				else if(arg0=="七日趋势"){
					i.setClass(City_view.this,TodayWeatherActivity.class);
					startActivity(i);
				}
				else if(arg0=="城市管理"){
					i.setClass(City_view.this,City_view.class);
					startActivity(i);
				}
				else if(arg0=="指数信息"){
					i.setClass(City_view.this,TodayWeatherActivity.class);
					startActivity(i);
				}
			}
		});*/
        initData();
        initView();	
        add_view= (ImageView)findViewById(R.id.add_view);
        add_view.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent i  =new Intent();
				i.setClass(City_view.this,City_add.class);
				startActivity(i);
			}
		});
        
    }

    private void initData() {				//鍒濆鍖栧煄甯備俊鎭�
		
    	for(int i=0;i<3;i++){
    		CityInfo msg = null;
    		if(i%3==0){
    			msg = new CityInfo("北京市", "早上8:44", "28℃");
    			msg.setIcon_id(R.drawable.clound);
    		}else if(i%3==1){
    			msg = new CityInfo("上海市", "早上8:49","32℃");
    			msg.setIcon_id(R.drawable.rain);
    		}else{
    			msg = new CityInfo("天津市", "下午2:00","26℃");
    			msg.setIcon_id(R.drawable.sunshine);
    		}
    		
    		data.add(msg);
    	}
	}
    
	/**
     * 
     */
    private void initView() {
    	
        mListView = (SwipeListView)findViewById(R.id.listview);
        final SwipeAdapter mAdapter = new SwipeAdapter(this,data,mListView.getRightViewWidth());
        
        mAdapter.setOnRightItemClickListener(new SwipeAdapter.onRightItemClickListener() {
        	
                    @Override
                    public void onRightItemClick(View v, int position) {
                    	mListView.deleteItem(mListView.getChildAt(position));
                    	data.remove(position);
                    	mAdapter.notifyDataSetChanged();
                    	CustomToast.showToast(City_view.this,  "鍒犻櫎绗�  " + (position+1)+" 瀵硅瘽璁板綍", 1000);
                    }
                });
        
        mListView.setAdapter(mAdapter);
        
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            	CustomToast.showToast(City_view.this,  "item onclick " + position, 1000);
            }
        });
    }
}
